package com.elangzhi.ssm.modules.type.app;

import com.elangzhi.ssm.controller.json.Tip;
import com.elangzhi.ssm.model.Type;
import com.elangzhi.ssm.modules.type.services.TypeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
* 分类 客户端 Controller
* @author GaoXiang
* @version 1.0
*/
@Controller
@RequestMapping("/app/type")
public class AppTypeController {


    /**
     * 获取某分类下级分类
     * @param parentId 分类分类
     * @return 分类列表
     */
    @RequestMapping("listByParentId")
    @ResponseBody
    public List<Type> listByParentId(Long parentId){
        return  typeService.listByParentId(parentId);
    }

    /**
     * 获取全部顶级分类
     * @return 顶级分类列表
     */
    @RequestMapping("listTop")
    @ResponseBody
    public List<Type> listTop(){
        return  typeService.listTop();
    }

    /**
     * 删除分类和分类下级
     * @param id 要删除的id
     * @return 返回状态
     */
/*    @RequestMapping("deleteType")
    @ResponseBody
    public Tip deleteType(Long id){
        try {
            typeService.deleteById(id);
            typeService.deleteByParentId(id);
            return new Tip();
        } catch (Exception e) {
            e.printStackTrace();
            return new Tip(1);
        }
    }*/


    //---------------------------- property -------------------------------

    @Resource
    private TypeService typeService;

}
